package my.design.state;

import java.util.Date;

/**
 * @author zp
 * @version 1.0
 * @description: 管理数据类
 * @date 2022/10/30 16:53
 */
public class ActivityService {
    public ActivityInfo activityInfo;

    public ActivityService() {
        // 模拟查询活动信息
        ActivityInfo activityInfo = new ActivityInfo();
        activityInfo.setActivityId("100001");
        activityInfo.setActivityName("早起学习打卡领奖活动");
        activityInfo.setStatus(Status.Editing);
        activityInfo.setBeginTime(new Date());
        activityInfo.setEndTime(new Date());
        this.activityInfo = activityInfo;
    }

    public void init(String activityId, Enum<Status> status) {
        // 模拟查询活动信息
        ActivityInfo activityInfo = new ActivityInfo();
        activityInfo.setActivityId(activityId);
        activityInfo.setActivityName("早起学习打卡领奖活动");
        activityInfo.setStatus(status);
        activityInfo.setBeginTime(new Date());
        activityInfo.setEndTime(new Date());
        this.activityInfo = activityInfo;
    }

    public ActivityInfo getActivityInfo() {
        return this.activityInfo;
    }

    public void setActivityInfo(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    /**
     * 执⾏行行状态变更更
     *
     * @param beforeStatus 变更更前状态
     * @param afterStatus  变更更后状态 b
     */
    public synchronized void execStatus(Enum<Status> beforeStatus, Enum<Status> afterStatus) {
        if (!beforeStatus.equals(activityInfo.getStatus())) {
            return;
        }
        activityInfo.setStatus(afterStatus);
    }
}
